<?php
namespace App\Http\Controllers\Api\WMS;

use App\Http\Controllers\Controller;
use App\Model\WMS\Warehouse as ModelWarehouse;
use Illuminate\Http\Request;

class Warehouse extends Controller
{
    /**
     * 仓库列表
     * @param bool $status 启用与否
     * @param int $page 页数
     * @param int $perPage 每页数量
     */
    public function ls (Request $req)
    {
        $qry = ModelWarehouse::query();

        if ($req->type) {
            $qry->where('type', $req->type);
        }

        if($req->simple) { #无分页
            $res =  $qry->whereOn()->select('id','name')->get();
            return self::resSuccess('', $res);
        }

        $status = $req->get('status');
        if (strlen($status)) {
            $qry->whereOn($status);
        }
        $qry->orderBy('is_on')->orderBy('id', 'desc');
        $qry = $qry->paginate($req->get('per_page'));

        foreach ($qry->items() as $v) {
//            $v->_country = $v->translateProperty('country');
            $v->translateProperties();
        }

        return self::resSuccess('', $qry);
    }
}